import 'package:flutter/material.dart';
import 'package:intrinsic_grid_view/intrinsic_grid_view.dart';
import 'package:live_bg_mobile/widget/ripple_card_container.dart';

import '../common/util/common_util.dart';
import 'error_img.dart';

class ImgGridList extends StatelessWidget {
  final List<String> imgList;
  final bool imgViewerVisible;
  final int listColumnCount;
  final double listVerticalSpace;
  final double listHorizontalSpace;

  const ImgGridList(
      {Key? key, required this.imgList, this.imgViewerVisible = true,this.listColumnCount = 3,
        this.listVerticalSpace = 0,
        this.listHorizontalSpace = 5,})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return IntrinsicGridView.vertical(
        columnCount: listColumnCount,
        verticalSpace: listVerticalSpace,
        horizontalSpace: listHorizontalSpace,
        children: List.generate(
            imgList.length,
            (index) => RippleCardContainer(
                onTap: () {
                  if (imgViewerVisible) {
                    CommonUtil.showImgViewer(context, index, imgList);
                  }
                },
                child: Image.network(
                  imgList[index],
                  errorBuilder: (BuildContext context, Object error,
                          StackTrace? stackTrace) =>
                      const ErrorImg(),
                ))));
  }
}
